﻿Public Class ValiderDateDeVol1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub ValiderDateDeVol_ServerValidate(ByVal sender As Object, ByVal arg As System.Web.UI.WebControls.ServerValidateEventArgs)

        AfficherResultat.Text = ""

        Dim boolValidDateDepart As Boolean = True
        Dim boolValidDateRetour As Boolean = True

        Try
            Date.Parse(txtDateDeDepart.Text)
            arg.IsValid = True
        Catch ex As Exception
            boolValidDateDepart = False
        End Try

        Try
            Date.Parse(txtDateArrivee.Text)
            arg.IsValid = True
        Catch ex As Exception
            boolValidDateRetour = False
        End Try

        If boolValidDateDepart And boolValidDateRetour Then

            Dim dateDepartParsed As Date = txtDateDeDepart.Text
            Dim dateRetourParsed As Date = txtDateArrivee.Text

            If (Date.Compare(dateDepartParsed, Date.Today) = 1) And (Date.Compare(dateDepartParsed, Date.Today) = 1) Then

                If Not (dateRetourParsed > dateDepartParsed) Then
                    CValidator.ErrorMessage = "Votre date de retour doit être supérieure à votre date d'arrivée."
                    arg.IsValid = False
                End If
            Else
                CValidator.ErrorMessage = "Votre date de départ ou d'arrivée ne peut être fixée ou être antérieure à la date du jour."
                arg.IsValid = False
            End If
        Else
            CValidator.ErrorMessage = "Veuillez respecter la saisie des dates de départ et d'arrivée au format : JJ/MM/AA."
            arg.IsValid = False
        End If

    End Sub



    Private Sub ValiderDateDeVol1_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        Try
            If Me.IsValid Then
                Dim dateDepartParsed As Date = txtDateDeDepart.Text
                Dim dateRetourParsed As Date = txtDateArrivee.Text
                AfficherResultat.Text = "Succes votre voyage a New-York est reserve du " & dateDepartParsed.ToLongDateString() & " au " & dateRetourParsed.ToLongDateString()
            End If
        Catch ex As Exception
        End Try


    End Sub
End Class